// pages/goods/store/store.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		id: 28745,
		http: getApp().globalData.map,
		px: 0,
		xin: 1,
		brand: '',
		list: [],
		brand: 0,
		height: '100rpx',
		pd1: 0
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		this.setData({
			id: options.id
		})
	},
	zonghe() {
		this.setData({
			px: 0,
			list: [],
			zt: false,
			pg: 1,
		})
		this.push()
	},
	add() {
		if (this.data.uid != '') {
			wx.request({
				url: getApp().globalData.http1 + 'action=gzShop&uid=' + this.data.uid + '&shopID=' + this.data.data.ShopID,
				success: (e) => {
					console.log(e)
					wx.showToast({
						icon: 'none',
						title: e.data.msg
					})
					this.setData({
						sc: !(this.data.sc)
					})
				}
			})
		} else {
			wx.navigateTo({
				url: '../register/register'
			})
		}
	},
	onShow() {
		this.setData({
			xin: 1,
			pg: 1,
			list: []
		})
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data.uid
				})
				console.log(this.data.uid)
				this.push()
			}
		})
	},
	push() {
		wx.request({
			url: getApp().globalData.http1 + 'action=showShop&shopID=' + this.data.id + '&uid=' + this.data.uid +
				'&classID=' + this.data.brand + '&key=&pg=1&px=' + this.data.px,
			success: (e) => {
				console.log(e)
				let a = this.data.list
				let pd = 1
				if (this.data.xin == 1) {
					a = []
					if (e.data.data.length < 15) {
						pd = 0
					}
					for (let i in e.data.data.goodList) {
						a.push(e.data.data.goodList[i])
					}
				} else {
					for (let i in e.data.data.goodList) {
						a.push(e.data.data.goodList[i])
					}
				}
				this.setData({
					pd: 0,
					data: e.data.data,
					list: a,
					xin: 0,
					sc: e.data.data.isGZ
				})
			}
		})
	},
	ovo() {
		if (this.data.pd == 1) {
			this.setData({
				pg: this.data.pg + 1
			})
			this.push()
		}
	},
	pd() {
		this.setData({
			pd1: !(this.data.pd1)
		})
		var query = wx.createSelectorQuery();
		//选择id
		var that = this;
		query.select('.information').boundingClientRect(function(rect) {
			console.log(rect)
			that.setData({
				height: rect.height + 'rpx'
			})
		}).exec();
	},
	jiage() {
		if (this.data.px == 2) {
			this.setData({
				px: 1,
				list: [],
				zt: false,
				pg: 1
			})
			this.push()
		} else {
			this.setData({
				px: 2,
				list: [],
				zt: false
			})
			this.push()
		}
		console.log(this.data.px)
	},
	xl() {
		this.setData({
			px: 3,
			list: [],
			zt: false,
			pg: 1,
		})
		this.push()
	},
})
